package com.autumn.cloud.demo.consumer.controllers.order;

import com.autumn.cloud.demo.common.constants.DemoServiceProviderUrlConstants;
import com.autumn.cloud.demo.common.model.OrderInfo;
import com.autumn.cloud.demo.consumer.client.DemoFeignClient;
import com.autumn.cloud.demo.consumer.utils.HystrixUtils;
import com.autumn.web.vo.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * </p>
 *
 * @description TODO
 * @author: 老码农
 * @create: 2020-12-11 17:19
 **/
@RestController
@Slf4j
public class OrderController {

    private final DemoFeignClient demoFeignClient;

    public OrderController(DemoFeignClient demoFeignClient) {
        this.demoFeignClient = demoFeignClient;
    }

    /**
     * 订单信息
     *
     * @return
     */
    @GetMapping(path = DemoServiceProviderUrlConstants.ORDER_INFO_URL)
    public OrderInfo orderInfo() {
        log.info("订单服务器");
        ApiResponse<OrderInfo> response = this.demoFeignClient.getOrderInfo();
        if (response.isSuccess()) {
            return response.getResult();
        }
        throw HystrixUtils.createApiException(response.getError());
    }

}
